<?php
	class Back_models extends CI_Model{
		function __Construct(){
			parent::__Construct();
		}
		function finduser($filter){
			$this->db->where($filter);
			$query = $this->db->get("tbl_user");
			return $query->row_array();
		}
		function get_news($fillter){
			$where = $limit ="";
			if(isset($fillter['key'])){
				$where .="and news_name like'%".$fillter['key']."%'";
			}
			if(isset($fillter['page'])){
				
				$limit .=" LIMIT ".$fillter['start'].",".$fillter['limit']."";
			}
			//echo "SELECT * FROM news WHERE 1=1 $where $limit";die;
			$query=$this->db->query("SELECT * FROM news WHERE 1=1 $where $limit");
			
			return $query->result_array();
		}
		function insert($data){
			$this->db->insert("news",$data);
		}
		function delete($id){
			$this->db->where("id",$id);
			$this->db->delete("news");
		}
		function update($id,$fillter){
			$this->db->where("user_id",$id);
			$this->db->update("tbl_user",$fillter);
		}
		function update_news($id,$fillter){
			$this->db->where("id",$id);
			$this->db->update("news",$fillter);
		}
		// product
		
		function getproduct($fillter){
			$where=$limit ="";
			if(isset($fillter['key'])){
				$where .="and name = '".$fillter['key']."'";
			}
			if(isset($fillter['limit'])){
				$limit .= " limit ".$fillter['start'].",".$fillter['limit']."";
			}
			$query =$this->db->query("select * from product where 1=1 $where $limit");
			return $query->result_array();
		}
		function getcategory(){
			$this->db->select("*");
			$query= $this->db->get("tbl_category");
			return $query->result_array();
		}
		function update_cate($id,$fillter){
			$this->db->where("cate_id",$id);
			$this->db->update("tbl_category",$fillter);
		}
	}
?>